package facade

import (
	"github.com/kataras/iris/v12/httptest"
	"{{.Namespace}}/pkg/query-service/infrastructure/test"
	"{{.Namespace}}/pkg/query-service/userinterface/rest/{{.aggregate_name}}/dto"
	"testing"
)

func Test{{.Name}}QueryApi(t *testing.T) {
	e := httptest.New(t, app)

	ids := []string{""}
	tenantId := test.TenantId

	t.Run("FindAll", func(t *testing.T) {
		var list []*dto.{{.Name}}Dto
		resp := e.GET("/api/v1.0/tenants/{tenantId}/{{.AggregatePath}}{{.PluralName}}:all", tenantId).Expect().Status(httptest.StatusOK)
		if err := test.GetResponseData(t, resp, &list); err != nil {
			t.Error(err)
		}
		for _, item := range list {
			ids = append(ids, item.Id)
		}
	})

	t.Run("FindPaging", func(t *testing.T) {
		var data dto.{{.Name}}FindPagingResponse
		resp := e.GET("/api/v1.0/tenants/{tenantId}/{{.AggregatePath}}{{.PluralName}}", tenantId).Expect().Status(httptest.StatusOK)
		if err := test.GetResponseData(t, resp, &data); err != nil {
			t.Error(err)
		}
	})

	t.Run("FindById", func(t *testing.T) {
		var data *dto.{{.Name}}FindByIdResponse
		resp := e.GET("/api/v1.0/tenants/{tenantId}/{{.AggregatePath}}{{.PluralName}}/{id}", tenantId, ids[len(ids)-1]).Expect().Status(httptest.StatusOK)
		if err := test.GetResponseData(t, resp, &data); err != nil {
			t.Error(err)
		}
	})

	t.Run("FindByIds", func(t *testing.T) {
		var data *dto.{{.Name}}FindByIdsResponse
		resp := e.GET("/api/v1.0/tenants/{tenantId}/{{.AggregatePath}}{{.PluralName}}:ids", tenantId, ids).Expect()
		if err := test.GetResponseData(t, resp, &data); err != nil {
			t.Error(err)
		}
	})


    {{- if .IsEntity}}
	t.Run("FindBy{{.AggregateName}}Id", func(t *testing.T) {
		var data *dto.{{.Name}}FindByIdsResponse
		{{.aggregateName}}Id := "{{.AggregateName}}Id"
		resp := e.GET("/api/v1.0/tenants/{tenantId}/{{.AggregatePluralName}}/{{.PluralName}}:{{.aggregateName}}Id?{{.aggregateName}}Id='%v'", tenantId, {{.aggregateName}}Id).Expect()
		if err := test.GetResponseData(t, resp, &data); err != nil {
			t.Error(err)
		}
	})
	{{- end }}

}



